//
//  CheekScreeningCell.m
//  CheekiOS
//
//  Created by mac on 2017/7/10.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "CheekScreeningCell.h"

@implementation CheekScreeningCell

+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath*)indexPath {
        static NSString *CheekScreeningCellIdent = @"CheekScreeningCellIdent";
    CheekScreeningCell *cell = [tableView dequeueReusableCellWithIdentifier:CheekScreeningCellIdent];
    if (!cell) {
        cell = [[CheekScreeningCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CheekScreeningCellIdent];
        
    }
    cell.indexpath = indexPath;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    
    return cell;
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        
        self.imgView = [[UIImageView alloc] init];
        [self addSubview:self.imgView];
    
        
        self.nameLabel = [[UILabel alloc]init];
        self.nameLabel.font = FontP(15);
        self.nameLabel.textColor = [UIColor blackColor];
        self.nameLabel.textAlignment = NSTextAlignmentLeft;
        
        [self addSubview:self.nameLabel];
        
        
       
  
        self.charmLab = [[UILabel alloc]init];
        self.charmLab.font = FontP(15);
        self.charmLab.textColor = ColorI(0x2e353f);
        self.charmLab.textAlignment = NSTextAlignmentLeft;
        
        [self addSubview:self.charmLab];
        
   
        
        self.button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.button setBackgroundImage:[UIImage imageNamed:@"bjzl_emotion_choice_button"] forState:UIControlStateNormal];
        [self.button setBackgroundImage:[UIImage imageNamed:@"bjzl_emotion_choice_button_p"] forState:UIControlStateSelected];
        [self addSubview:self.button];
        
        [self.button addTarget:self action:@selector(buttonActionClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(15);
            make.height.mas_equalTo(50*SCREEN_WIDTH_RATIO47);
            make.width.mas_equalTo(50*SCREEN_WIDTH_RATIO47);
        }];
        
        [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.imgView.mas_right).offset(15);
            make.height.mas_equalTo(25*SCREEN_WIDTH_RATIO47);
            make.top.equalTo(self).offset(12.5);
        }];
        
        
        
        [self.charmLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.imgView.mas_right).offset(15);
            make.height.mas_equalTo(25*SCREEN_WIDTH_RATIO47);
            make.top.equalTo(self.nameLabel.mas_bottom).offset(0);
        }];
        
        
        
        
        UIView *linView = [[UIView alloc] init];
        linView.backgroundColor = RGB(243, 243, 243);
        [self addSubview:linView];
        [linView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.left.equalTo(self);
            make.height.mas_equalTo(1);
            make.top.equalTo(self.mas_bottom);
        }];
        
        
        [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-15);
            make.height.mas_equalTo(25*SCREEN_WIDTH_RATIO47);
            make.width.mas_equalTo(25*SCREEN_WIDTH_RATIO47);
            make.top.mas_equalTo(25*SCREEN_WIDTH_RATIO47);
        }];
        
        
    }
    return self;
}

-(void)setModel:(UserEditEmotinalModel *)model{

    
    _model = model;
   
    if (_indexpath.row != 3) {
        self.nameLabel.text = model.title;
        self.charmLab.text = model.charm;
        self.imageView.image = [UIImage imageNamed:model.imagePath];
        self.button.tag = _indexpath.row;
        self.button.selected = model.isSelect;
        
    }else{
        self.nameLabel.hidden = YES;
        self.charmLab.hidden = YES;
        self.imageView.hidden = YES;
//        self.button.tag = _indexpath.row;
//        self.button.selected = model.isSelect;
        self.button.hidden = YES;
    }
    
    

 

}

- (void)buttonActionClick:(UIButton *)button{
    
    if ([self.delegate respondsToSelector:@selector(userEditEmotinalCell:clickBtn:)]) {
        [self.delegate userEditEmotinalCell:self clickBtn:button];
    }
    
}

@end
